package ran.controller.question;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ran.controller.BaseController;
import ran.domain.question.dto.QuestionAddDTO;
import ran.domain.question.dto.QuestionEditDTO;
import ran.domain.question.dto.QuestionQueryDTO;
import ran.domain.question.vo.QuestionDetailVO;
import ran.domain.question.vo.QuestionVO;
import ran.entity.Result;
import ran.entity.TableDataInfo;
import ran.service.question.IQuestionService;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ran
 * Date: 2025-10-16
 * Time: 17:18
 */
@RestController
@RequestMapping("/question")
@Tag(name = "题目API")
public class QuestionController extends BaseController {

    @Autowired
    IQuestionService questionService;
    // 所有题目列表展示
    @GetMapping("/list")
    public TableDataInfo list(QuestionQueryDTO questionQueryDTO) {
        List<QuestionVO> list = questionService.list(questionQueryDTO);
        return toTableDataInfo(list);
    }
    // 添加题目
    @PostMapping("/add")
    public Result<Void> add(@RequestBody @Validated QuestionAddDTO questionAddDTO) {
        return toResult(questionService.add(questionAddDTO));
    }
    // 获取单个题目详情
    @GetMapping("/detail")
    public Result<QuestionDetailVO> detail(Long questionId) {
        return Result.ok(questionService.detail(questionId));
    }
    // 编辑题目
    @PutMapping("/edit")
    public Result<Void> edit(@RequestBody @Validated QuestionEditDTO questionEditDTO) {
        return toResult(questionService.edit(questionEditDTO));
    }
    // 删除题目
    @DeleteMapping("/delete")
    public Result<Void> delete(Long questionId) {
        return toResult(questionService.delete(questionId));
    }

}
